<?php


namespace app\api\controller;


use app\api\logic\GoodsLogic;
use app\common\controller\BaseApiController;

/**
 * 商品
 * Class GoodsController
 * @package app\api\controller
 */
class GoodsController extends BaseApiController
{
    protected $noNeedLogin = ['*'];

    protected function init()
    {
        parent::init();
        $this->logic = new GoodsLogic();
    }

    public function page()
    {
        return $this->success($this->logic->goodsPage($this->form));
    }

    public function detail()
    {
        if ($id = input('id')) {
            return $this->success($this->logic->goodsDetail(input('id')));
        }
        return $this->success();
    }

    /**
     * 首页推荐
     */
    public function homeGoods()
    {
        return $this->success($this->logic->homeGoods());
    }

    /**
     * 分类精选
     */
    public function recommendCateGoods()
    {
        return $this->success($this->logic->recommendCateGoods());
    }

    /**
     * 搜索页推荐
     */
    public function searchPageGoods()
    {
        return $this->success($this->logic->searchPageGoods());
    }

    /**
     * 热门搜索
     */
    public function hotSearchKeyword()
    {
        return $this->success($this->logic->hotSearchKeyword());
    }

    /**
     * 新增商品浏览记录
     */
    public function browse()
    {
        if (request()->uid) {
            $this->logic->addGoodsBrowse(input('goods_id'));
        }
        return $this->success();
    }

    /**
     * 取消收藏
     */
    public function unCollectGoods()
    {
        $goods_id = input('goods_id');
        $this->logic->unCollectGoods($goods_id);
        return $this->success();
    }

    /**
     * 收藏
     */
    public function collectGoods()
    {
        $goods_id = input('goods_id');
        $this->logic->collectGoods($goods_id);
        return $this->success();
    }
}